package cn.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import cn.bean.Log;
import cn.dao.LogDao;
import cn.dao.UserDao;
import cn.dao.impl.LogDaoImpl;
import cn.dao.impl.UserDaoImpl;
import cn.service.RegisterService;

public class RegisterServiceImpl implements RegisterService
{
    LogDao ld=new LogDaoImpl();
    UserDao ud=new UserDaoImpl();
	@Override
	public boolean judgeAccount(String account)
	{
		boolean isFlag=false;
		List<Log> ll=new ArrayList<Log>();
		ll=ld.findAllLog();
		for(Log l:ll)
		{
			if(account.equals(l.getAccount()))
			{
				isFlag=true;
			}
		}
		return isFlag;
	}

	@Override
	public boolean judgePassword(String password)
	{
		boolean isFlag=false;
		if(password.length()<6)
		{
			isFlag=true;
		}
			
		return isFlag;
	}

	@Override
	public boolean doLog(String account, String password, String name,
			String phone, double money)
	{
		boolean isFlag=true;

		if(judgePassword(password))
		{
			isFlag=false;
		}
		
		else
		{
			
			ld.doLog(account, password);
			ud.doUser(name, phone, money,ld.findLogByAcc(account));		
		}
		return isFlag;
	}

	@Override
	public boolean judgeMoney(String money)
	{
		boolean isFlag=false;
		Pattern p=Pattern.compile("^[-\\+]?[.\\d]*$");
		if(p.matcher(money).matches())
		{
			isFlag=true;
		}
		return false;
	}

}
